"""
Splitter window contains the mail list and the view container
Written By: Daniel Ortiz
"""
import wx
from maillist import MailTreeList, FolderTree, MailList
from notepad import MailFlatNotebook

class LTSplitter(wx.SplitterWindow):
    """Splitter window contains the MailList and the FolderTree"""
    def __init__(self, parent):
        self.parent = parent
        wx.SplitterWindow.__init__(self, parent)
        self.InitializeChildren()
        self.AddChildren()
        
    def InitializeChildren(self):
        """Initialize the children of the splitter window"""
        self.folder_tree = FolderTree(self)
        self.mail_list = MailList(self)
        self.folder_tree.AddList(self.mail_list)
        self.mail_list.BindTree(self.folder_tree)
        
    def AddChildren(self):
        """Add the children to the splitter window"""
        self.SetMinimumPaneSize(250)
        self.SplitVertically(self.folder_tree, self.mail_list)
        self.SetSashPosition(250)
        

class MailSplitter(wx.SplitterWindow):
    def __init__(self, parent):
        wx.SplitterWindow.__init__(self, parent, style = wx.SP_LIVE_UPDATE | wx.SP_3D)
        self.InitializeChildren()
        self.AddChildren()
        self.BindEvents()
        
    def InitializeChildren(self):
        """Initialize the two windows which are contained inside the splitter"""
        #self.mail_list = MailList(self)
        self.mail_list = LTSplitter(self)
        self.mail_notebook = MailFlatNotebook(self)

    def AddChildren(self):
        """Add the children to the splitter window"""
        self.SetMinimumPaneSize(150)
        self.SplitHorizontally(self.mail_list, self.mail_notebook)
        self.SetSashPosition(150)
        
    def BindEvents(self):
        """Bind the relevant wx events to the window"""
        self.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGED, self.OnSashChange)
        self.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGING, self.OnSashChanging)
        
    def OnSashChanging(self, event):
        """Send out a continuous size event to the mail browser"""
        self.mail_notebook.BeginSash()
        self.Refresh()
        
    def OnSashChange(self, event):
        """Throw size events as the sash is changing"""
        self.mail_notebook.EndSash()
        
    def GetCurrentNotebookPage(self):
        """Return the current notebook page"""
        return self.mail_notebook.GetCurrentPage()
